package com.gz.rabbitmq.topic;

import com.gz.rabbitmq.utils.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static String EX_CHANGE_NAE = "topic_exchange";

    public static String TOPIC_QUEUE_1 = "topic_queue_1";

    public static String TOPIC_QUEUE_2 = "topic_queue_2";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection("demo");

        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EX_CHANGE_NAE, BuiltinExchangeType.TOPIC);

        channel.queueDeclare(TOPIC_QUEUE_1, true, false, false, null);

        channel.queueDeclare(TOPIC_QUEUE_2, true, false, false, null);

        channel.queueBind(TOPIC_QUEUE_1, EX_CHANGE_NAE, "rabbit.insert");

        channel.queueBind(TOPIC_QUEUE_2, EX_CHANGE_NAE, "rabbit.update");

        String insert = "插入语句";

        channel.basicPublish(EX_CHANGE_NAE, "rabbit.insert", null, insert.getBytes());

        String update = "修改语句";

        channel.basicPublish(EX_CHANGE_NAE, "rabbit.update", null, update.getBytes());

        channel.close();

        connection.close();
    }
}
